package com.rajaev.dtu.tractor.domain.repository.mongo;

import cn.hutool.core.date.DateUtil;
import com.rajaev.dtu.tractor.infrastructure.helper.MongoDbUtils;
import org.bson.Document;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Component
public class DeviceGpsMongoRepository {

    @Resource
    public MongoDbUtils mongoDbUtils;

    private final static String collection_name = "DEVICE_LOCATION";

    public void saveDeviceGps(String vin,double lat,double lng,long timestamp){
        Map map = new HashMap<>();
        map.put("vin", vin);
        map.put("tickTime", timestamp);
        map.put("log_date", DateUtil.format(new Date(timestamp * 1000), "yyyyMMdd"));
        map.put("lat", lat);
        map.put("lng", lng);
        Document document = new Document(map);
        mongoDbUtils.getDatabase().getCollection(collection_name).insertOne(document);
    }


}
